package com.robusta.spreadsheet.model;

import com.google.common.io.Resources;

import java.io.File;
import java.util.List;

import static com.google.common.collect.Lists.newArrayList;

public class RobustaModelTestFixture {
    public static final WorksheetTemplate WORKSHEET_TEMPLATE = new TestWorksheetTemplate(0, 1, 1);
    public static final WorksheetTemplate INVALID_WORKSHEET_TEMPLATE = new TestWorksheetTemplate(1, 1, 1);
    public static final WorkbookTemplate WORKBOOK_TEMPLATE = new TestWorkbookTemplate();
    public static final Workbook WORKBOOK;
    public static final File WORKBOOK_FILE;
    public static final File NOT_A_VALID_FILE;
    public static final Worksheet WORKSHEET;
    public static final SheetHeaders SHEET_HEADERS;
    public static final Row ROW;
    public static final Cell CELL;

    static {
        try {
            WORKBOOK_FILE = new File(Resources.getResource("test.xlsx").getFile());
            NOT_A_VALID_FILE = new File("NotAValidFile.xlsx");
            WORKBOOK = new RobustaWorkbookFixture();
            WORKSHEET = WORKBOOK.getSheetFor(WORKSHEET_TEMPLATE);
            SHEET_HEADERS = WORKSHEET.getHeaders();
            ROW = WORKSHEET.getRowAt(5);
            CELL = ROW.getCellAt(5);
        } catch (Exception e) {
            throw new RuntimeException("Test fixture initialization has failed", e);
        }
    }

    static class TestWorksheetTemplate implements WorksheetTemplate {
        private int spreadsheetIndex;
        private int startRowIndex;
        private int startColumnIndex;

        public TestWorksheetTemplate(int spreadsheetIndex, int startRowIndex, int startColumnIndex) {
            this.spreadsheetIndex = spreadsheetIndex;
            this.startRowIndex = startRowIndex;
            this.startColumnIndex = startColumnIndex;
        }

        @Override
        public int getSheetIndex() {
            return spreadsheetIndex;
        }

        @Override
        public int getHeaderRowIndex() {
            return startRowIndex;
        }

        @Override
        public int getStartColumnIndex() {
            return startColumnIndex;
        }

        @Override
        public String toString() {
            return "TestWorksheetTemplate{" +
                    "spreadsheetIndex=" + spreadsheetIndex +
                    ", startRowIndex=" + startRowIndex +
                    ", startColumnIndex=" + startColumnIndex +
                    '}';
        }
    }

    static class TestWorkbookTemplate implements WorkbookTemplate {
        @Override
        public List<WorksheetTemplate> getSpreadsheetTemplates() {
            return newArrayList((WorksheetTemplate) WORKSHEET_TEMPLATE);
        }
    }

}